/* 补贴规则管理样式
------------------------------- */

// 基础样式
.subsidy-rule {
  .form-section {
    margin-bottom: 30px;

    .section-title {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 20px;
      padding-bottom: 10px;
      color: var(--el-text-color-primary);
      font-size: 16px;
      font-weight: 600;

      i {
        color: var(--el-color-primary);
        font-size: 18px;
      }
    }
  }

  // 公式输入组样式
  .formula-input-group {
    display: flex;
    gap: 12px;
    align-items: flex-start;

    .el-input {
      flex: 1;
    }

    .el-button {
      white-space: nowrap;
    }
  }

  // 公式对话框样式
  .formula-dialog-content {
    padding: 0;

    .formula-info {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 12px 16px;
      background-color: var(--el-color-info-light-9);
      border: 1px solid var(--el-color-info-light-5);
      border-radius: 6px;
      margin-bottom: 20px;
      color: var(--el-color-info-dark-2);
      font-size: 14px;
    }

    .formula-editor-container {
      display: flex;
      gap: 20px;
      min-height: 400px;

      .field-selector {
        width: 250px;
        border: 1px solid var(--el-border-color);
        border-radius: 6px;
        background-color: var(--el-fill-color-lighter);

        .field-search {
          padding: 12px;
          border-bottom: 1px solid var(--el-border-color);
        }

        .field-list {
          padding: 0;

          .field-group-title {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 16px;
            cursor: pointer;
            font-weight: 500;
            color: var(--el-text-color-primary);
            background-color: var(--el-fill-color);
            border-bottom: 1px solid var(--el-border-color);

            &:hover {
              background-color: var(--el-color-primary-light-9);
            }

            .el-icon {
              transition: transform 0.3s ease;

              &.is-expanded {
                transform: rotate(180deg);
              }
            }
          }

          .field-items {
            padding: 0;

            .field-item {
              padding: 10px 16px;
              cursor: pointer;
              border-bottom: 1px solid var(--el-border-color-extra-light);
              font-size: 14px;
              color: var(--el-text-color-regular);
              transition: background-color 0.2s ease;

              &:hover {
                background-color: var(--el-color-primary-light-9);
                color: var(--el-color-primary);
              }

              &:last-child {
                border-bottom: none;
              }
            }
          }
        }
      }

      .formula-editor {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 16px;

        .operator-buttons {
          display: flex;
          gap: 8px;
          flex-wrap: wrap;

          .el-button {
            min-width: 40px;
            height: 32px;
            font-size: 16px;
            font-weight: 500;
          }
        }

        .operation-guide {
          display: flex;
          justify-content: flex-end;
        }

        .formula-input-area {
          flex: 1;

          .el-textarea {
            height: 100%;

            .el-textarea__inner {
              font-family: 'Courier New', monospace;
              font-size: 14px;
              line-height: 1.5;
            }
          }
        }

        .formula-example {
          padding: 12px;
          background-color: var(--el-fill-color);
          border: 1px solid var(--el-border-color-light);
          border-radius: 6px;

          .el-checkbox {
            font-size: 14px;
            color: var(--el-text-color-regular);
          }
        }
      }
    }

    .dialog-footer {
      display: flex;
      justify-content: flex-end;
      gap: 12px;
      padding-top: 20px;
      border-top: 1px solid var(--el-border-color);
    }
  }

  // 条件设置容器样式
  .conditions-container {
    margin-top: 16px;
    padding: 16px;
    background: var(--el-fill-color-lighter);
    border: 1px solid var(--el-border-color-light);
    border-radius: 8px;

    .conditions-table-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 8px 12px;
      background: var(--el-fill-color);
      border-radius: 6px;
      margin-bottom: 12px;
      font-weight: 600;
      color: var(--el-text-color-regular);
      font-size: 13px;

      .header-condition {
        flex: 1;
      }

      .header-status {
        text-align: right;
        min-width: 80px;
      }
    }

    .condition-item {
      border: 1px solid var(--el-border-color-light);
      border-radius: 8px;
      margin-bottom: 12px;
      padding: 12px 16px;
      background-color: var(--el-bg-color);
      transition: all 0.3s ease;

      &:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        transform: translateY(-1px);
      }

      &.disabled {
        opacity: 0.6;
        background-color: var(--el-fill-color-lighter);

        .condition-text,
        .condition-unit {
          color: var(--el-text-color-placeholder) !important;
        }
      }

      &:last-child {
        margin-bottom: 0;
      }

      .condition-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 10px;
        padding-bottom: 8px;
        border-bottom: 1px solid var(--el-border-color-extra-light);

        .condition-label {
          display: flex;
          align-items: center;
          gap: 6px;
          font-weight: 600;
          color: var(--el-text-color-primary);
          font-size: 14px;

          .condition-icon {
            color: var(--el-color-primary);
            font-size: 16px;
          }
        }

        .condition-switch {
          display: flex;
          align-items: center;
        }
      }

      .condition-content {
        padding-left: 0;
        margin-top: 8px;

        .condition-row {
          display: flex;
          align-items: center;
          flex-wrap: wrap;
          gap: 8px;

          .condition-text {
            min-width: 120px;
            font-weight: 500;
            color: var(--el-text-color-regular);
            font-size: 13px;
          }

          .condition-input {
            width: 120px;
          }

          .condition-unit {
            color: var(--el-text-color-regular);
            font-size: 13px;
          }

          .time-range {
            display: flex;
            align-items: center;
            gap: 6px;
            flex-wrap: wrap;
            flex: 1;
            min-width: 0;

            .time-selector {
              display: flex;
              align-items: center;
              gap: 4px;
              background: var(--el-fill-color);
              padding: 3px 6px;
              border-radius: 4px;
              border: 1px solid var(--el-border-color-light);
              min-width: 0;
              flex-shrink: 0;

              .day-select {
                width: 80px;
                min-width: 80px;
              }

              .time-picker {
                width: 110px;
                min-width: 110px;
              }
            }

            .time-separator {
              margin: 0 6px;
              color: var(--el-text-color-regular);
              font-weight: 500;
              font-size: 13px;
            }
          }
        }
      }
    }

    // 表格样式（用于条件设置）
    .punch-settings-table {
      background: var(--el-fill-color-lighter);
      border: 1px solid var(--el-border-color-light);
      border-radius: 6px;
      overflow: hidden;

      .punch-table-header {
        display: flex;
        background: var(--el-fill-color);
        border-bottom: 1px solid var(--el-border-color-light);
        font-weight: 600;
        color: var(--el-text-color-regular);
        font-size: 13px;
      }

      .punch-table-row {
        display: flex;
        border-bottom: 1px solid var(--el-border-color-extra-light);
        background: var(--el-bg-color);
        transition: background-color 0.2s ease;

        &:last-child {
          border-bottom: none;
        }

        &:hover {
          background: var(--el-fill-color-lighter);
        }

        &.disabled {
          opacity: 0.6;
          background-color: var(--el-fill-color-lighter);

          .condition-desc-text,
          .condition-unit {
            color: var(--el-text-color-placeholder) !important;
          }
        }
      }

      .header-col,
      .row-col {
        padding: 12px;
        display: flex;
        align-items: center;
      }

      // 条件类型列
      .col-condition-type {
        width: 120px;
        justify-content: flex-start;
      }

      // 条件描述列
      .col-condition-desc {
        flex: 1;
        min-width: 200px;
      }

      // 条件值列
      .col-condition-value {
        flex: 2;
        min-width: 300px;
      }

      // 开关列
      .col-condition-switch {
        width: 100px;
        justify-content: center;
      }

      .type-label {
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 13px;
        font-weight: 500;

        .type-icon {
          font-size: 16px;

          &.condition-attendance {
            color: var(--el-color-primary);
          }

          &.condition-checkin {
            color: var(--el-color-success);
          }

          &.condition-checkout {
            color: var(--el-color-warning);
          }
        }
      }

      .condition-desc-text {
        font-size: 13px;
        color: var(--el-text-color-regular);
        line-height: 1.4;
      }

      // 条件值组样式
      .condition-value-group {
        display: flex;
        align-items: center;
        gap: 8px;

        .condition-prefix {
          color: var(--el-text-color-secondary);
          font-weight: 500;
          margin-right: 4px;
        }

        .condition-input-number {
          width: 120px;
        }

        .condition-unit {
          color: var(--el-text-color-regular);
          font-size: 13px;
          margin-left: 4px;
        }
      }

      // 时间范围组样式
      .time-range-group {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-wrap: wrap;

        .time-group {
          display: flex;
          align-items: center;
          gap: 6px;

          .day-select-mini {
            width: 70px;
          }

          .time-picker-mini {
            width: 110px;
          }
        }

        .range-separator {
          color: var(--el-text-color-secondary);
          font-weight: 500;
          margin: 0 4px;
        }
      }
    }
  }
}

// 暗黑模式适配
[data-theme='dark'] {
  .subsidy-rule {
    .formula-info {
      background-color: var(--next-color-hover) !important;
      border-color: var(--next-border-color) !important;
      color: var(--next-color-bar) !important;
    }

    .field-selector {
      background-color: var(--next-color-primary) !important;
      border-color: var(--next-border-color) !important;

      .field-search {
        border-bottom-color: var(--next-border-color) !important;
      }

      .field-group-title {
        color: var(--next-color-bar) !important;
        background-color: var(--next-color-hover) !important;
        border-bottom-color: var(--next-border-color) !important;

        &:hover {
          background-color: var(--next-color-hover-rgba) !important;
        }
      }

      .field-item {
        color: var(--next-text-color-regular) !important;
        border-bottom-color: var(--next-border-color) !important;

        &:hover {
          background-color: var(--next-color-hover-rgba) !important;
          color: var(--el-color-primary) !important;
        }
      }
    }

    .formula-example {
      background-color: var(--next-color-hover) !important;
      border-color: var(--next-border-color) !important;

      .el-checkbox {
        color: var(--next-text-color-regular) !important;
      }
    }

    .dialog-footer {
      border-top-color: var(--next-border-color) !important;
    }

    .conditions-container {
      background: var(--next-color-primary) !important;
      border-color: var(--next-border-color) !important;

      .conditions-table-header {
        background: var(--next-color-hover) !important;
        color: var(--next-text-color-regular) !important;
      }

      .condition-item {
        background-color: var(--next-color-disabled) !important;
        border-color: var(--next-border-color) !important;

        &:hover {
          background-color: var(--next-color-hover) !important;
        }

        &.disabled {
          background-color: var(--next-color-primary) !important;
        }

        .condition-header {
          border-bottom-color: var(--next-border-color) !important;

          .condition-label {
            color: var(--next-color-bar) !important;
          }
        }

        .condition-text,
        .condition-unit {
          color: var(--next-text-color-regular) !important;
        }

        .time-selector {
          background: var(--next-color-hover) !important;
          border-color: var(--next-border-color) !important;
        }

        .time-separator {
          color: var(--next-text-color-regular) !important;
        }
      }
    }

    // 打卡设置表格暗黑模式适配
    .punch-settings-table {
      background: var(--next-color-primary) !important;
      border-color: var(--next-border-color) !important;

      .punch-table-header {
        background: var(--next-color-hover) !important;
        border-bottom-color: var(--next-border-color) !important;
        color: var(--next-text-color-regular) !important;
      }

      .punch-table-row {
        background: var(--next-color-disabled) !important;
        border-bottom-color: var(--next-border-color) !important;

        &:hover {
          background: var(--next-color-hover) !important;
        }

        &:last-child {
          border-bottom: none;
        }
      }
    }
  }
}

// 暗黑模式下的响应式适配
[data-theme='dark'] {
  @media (max-width: 1200px) {
    .subsidy-rule {
      .punch-settings-table {
        .punch-table-row {
          border-color: var(--next-border-color) !important;

          .row-col {
            &.col-condition-type {
              border-bottom-color: var(--next-border-color) !important;
            }
          }
        }
      }
    }
  }
}

// 响应式设计
@media (max-width: 1200px) {
  .subsidy-rule {
    .formula-editor-container {
      flex-direction: column;
      gap: 16px;

      .field-selector {
        width: 100%;
      }
    }

    .condition-row {
      .time-range {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;

        .time-separator {
          margin: 8px 0;
          align-self: center;
        }
      }
    }
  }
}

@media (max-width: 992px) {
  .subsidy-rule {
    .condition-row {
      gap: 8px;

      .time-range {
        gap: 5px;

        .time-selector {
          padding: 4px;

          .day-select {
            width: 75px;
            min-width: 75px;
          }

          .time-picker {
            width: 105px;
            min-width: 105px;
          }
        }
      }
    }
  }
}

@media (max-width: 768px) {
  .subsidy-rule {
    .form-section {
      margin-bottom: 25px;

      .section-title {
        font-size: 15px;
        margin-bottom: 15px;
      }
    }

    .formula-input-group {
      flex-direction: column;
      gap: 10px;

      .el-button {
        width: 100%;
      }
    }

    .formula-editor-container {
      min-height: 300px;

      .field-selector {
        .field-item {
          padding: 8px 12px;
          font-size: 13px;
        }
      }

      .operator-buttons {
        .el-button {
          min-width: 35px;
          height: 28px;
          font-size: 14px;
        }
      }
    }

    .conditions-container {
      padding: 12px;

      .conditions-table-header {
        flex-direction: column;
        gap: 6px;
        text-align: center;
        padding: 8px 12px;

        .header-condition,
        .header-status {
          text-align: center;
          font-size: 13px;
        }
      }

      .condition-item {
        padding: 12px;
        margin-bottom: 12px;

        .condition-header {
          flex-direction: column;
          align-items: flex-start;
          gap: 8px;
          margin-bottom: 8px;

          .condition-label {
            font-size: 13px;
          }
        }

        .condition-row {
          flex-direction: column;
          align-items: flex-start;
          gap: 12px;

          .condition-text {
            min-width: auto;
            font-size: 13px;
          }

          .condition-input {
            width: 100%;
          }

          .time-range {
            width: 100%;
            flex-direction: column;
            align-items: flex-start;
            gap: 8px;

            .time-selector {
              width: 100%;
              flex-direction: column;
              gap: 8px;
              padding: 8px;

              .day-select,
              .time-picker {
                width: 100%;
              }
            }

            .time-separator {
              margin: 4px 0;
              align-self: center;
              font-size: 13px;
            }
          }

          .condition-unit {
            font-size: 13px;
          }
        }
      }

      // 表格响应式样式
      .punch-settings-table {
        .punch-table-header {
          display: none; // 在移动端隐藏表头
        }

        .punch-table-row {
          flex-direction: column;
          border: 1px solid var(--el-border-color-light);
          border-radius: 8px;
          margin-bottom: 12px;
          padding: 12px;

          .row-col {
            padding: 8px 0;
            flex-direction: column;
            align-items: flex-start;
            width: 100%;

            &.col-condition-type {
              border-bottom: 1px solid var(--el-border-color-extra-light);
              padding-bottom: 12px;
              margin-bottom: 8px;
            }

            &.col-condition-switch {
              margin-top: 12px;
              align-items: center;
              justify-content: center;
            }
          }

          .condition-value-group,
          .time-range-group {
            width: 100%;
            flex-wrap: wrap;
            gap: 8px;

            .time-group {
              width: 100%;
              flex-direction: column;
              gap: 8px;

              .day-select-mini,
              .time-picker-mini {
                width: 100%;
              }
            }

            .range-separator {
              align-self: center;
              margin: 8px 0;
            }
          }
        }
      }
    }
  }
}

@media (max-width: 480px) {
  .subsidy-rule {
    .form-section {
      margin-bottom: 20px;

      .section-title {
        font-size: 14px;
        margin-bottom: 12px;
      }
    }

    .formula-editor-container {
      min-height: 250px;
      gap: 12px;

      .field-selector {
        .field-group-title {
          padding: 8px 12px;
          font-size: 13px;
        }

        .field-item {
          padding: 6px 12px;
          font-size: 12px;
        }
      }

      .operator-buttons {
        .el-button {
          min-width: 30px;
          height: 26px;
          font-size: 12px;
        }
      }

      .formula-input-area {
        .el-textarea__inner {
          font-size: 12px;
        }
      }
    }

    .conditions-container {
      padding: 8px;

      .condition-item {
        padding: 8px;
        margin-bottom: 8px;

        .condition-header {
          gap: 6px;
          margin-bottom: 6px;

          .condition-label {
            font-size: 12px;
          }
        }

        .condition-row {
          gap: 8px;

          .condition-text {
            font-size: 12px;
          }

          .time-selector {
            padding: 6px;

            .day-select,
            .time-picker {
              font-size: 12px;
            }
          }

          .condition-unit {
            font-size: 12px;
          }
        }
      }
    }
  }
}